package com.ldtk.wx.task;

import com.ldtk.wx.bean.AccessToken;
import com.ldtk.wx.utils.WeixinUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @ClassName:AccessTokenThread
 * @Description://TODO
 * @Authoe: hzh
 * @Time: 2018/11/711:53
 */
@Component
public class AccessTokenThread {
    private static Logger log = LoggerFactory.getLogger(AccessTokenThread.class);

    // 第三方用户唯一凭证
    public static String appid = "wx8b26e36c5a6b5cfd";

    // 第三方用户唯一凭证密钥
    public static String appsecret = "acfba01ae6b5ae098910979879e3ca97";
    // 第三方用户唯一凭证
    public static AccessToken accessToken = null;

    @Scheduled(fixedDelay = 2*3600*1000)
    //7200秒执行一次
    public void gettoken(){
        accessToken= WeixinUtil.getAccessToken(appid,appsecret);
        if(null!=accessToken){
            log.info("获取成功，accessToken:"+accessToken.getToken());
        }else {
            log.error("获取token失败");
        }
    }
}
